import { request, useUserStore, clearEmpty } from "jmash-core";
import qs from "qs";
import type { AxiosPromise } from "axios";
import type {
  TaskKey,
  FlowTaskModel,
  TaskReq,
  FlowTaskPage,
} from "../task/types";
import type { MonitorTaskApi, FlowSuspendTaskReq } from "./types";

class MonitorTaskApiImpl implements MonitorTaskApi {
  getKey(model: FlowTaskModel): TaskKey {
    return {
      taskId: model.id,
    } as TaskKey;
  }
  // 查询流程任务
  findPage(req: TaskReq): AxiosPromise<FlowTaskPage> {
    const tenant = useUserStore().user.tenant;
    clearEmpty(req);
    return request({
      url: "/v1/flow/task/page/" + tenant,
      method: "get",
      params: req,
    });
  }
  // 暂停/恢复任务.
  suspendTask(data: FlowSuspendTaskReq): AxiosPromise<boolean> {
    const tenant = useUserStore().user.tenant;
    clearEmpty(data);
    return request({
      url: "/v1/flow/task/suspend/" + tenant,
      method: "post",
      data: data,
    });
  }
}
const monitorTaskApi = new MonitorTaskApiImpl();

export { monitorTaskApi };
